#pragma once

//#include "Var.h"
//#include "ModelIndex.h"
//#include "ModelViewDefines.h"

#include <map>

namespace DuiLib
{
	class CAbstractItemModel;
	class CAbstractItemDelegate;

	class UILIB_API CAbstractItemView : virtual public DuiLib::CDuiObject
	{
		typedef std::map<int, CAbstractItemDelegate*> RowDelegateType;
		typedef std::map<int, CAbstractItemDelegate*> ColumnDelegateType;

	public:
		CAbstractItemView();
		virtual ~CAbstractItemView();

		CAbstractItemModel* model() const;
		virtual void setModel(CAbstractItemModel* pModel);

		void setItemDelegate(CAbstractItemDelegate *delegate);
		CAbstractItemDelegate *itemDelegate() const;

		void setItemDelegateForRow(int row, CAbstractItemDelegate *delegate);
		CAbstractItemDelegate *itemDelegateForRow(int row) const;

		void setItemDelegateForColumn(int column, CAbstractItemDelegate *delegate);
		CAbstractItemDelegate *itemDelegateForColumn(int column) const;

		CAbstractItemDelegate *itemDelegate(const CModelIndex &index) const;

	protected Dui_Slots:

		virtual void onDataChanged(const CModelIndex& index,
			const CVar& oldValue, const CVar& newValue) = 0;
		virtual void onHeaderDataChanged(int section, Orientation orient,
			const CVar& oldValue, const CVar& newValue);

		virtual void onRowsBefroreInsert(int row, int count, const CModelIndex& parent);
		virtual void onRowsInserted(int row, int count, const CModelIndex& parent);

		virtual void onRowsBefroreRemove(int row, int count, const CModelIndex& parent);
		virtual void onRowsRemoved(int row, int count, const CModelIndex& parent);

		virtual void onColumnBeforeInsert(int col, int count, const CModelIndex& parent);
		virtual void onColumnInserted(int col, int count, const CModelIndex& parent);

		virtual void onColumnBeforeRemove(int col, int count, const CModelIndex& parent);
		virtual void onColumnRemoved(int col, int count, const CModelIndex& parent);

		virtual void onRemoveAll(int rowCount);

	private:
		void DeleteAllDelegates();

	private:
		CAbstractItemModel*		m_Model;

		RowDelegateType			m_RowDelegates;
		ColumnDelegateType		m_ColumnDelegates;
		CAbstractItemDelegate*	m_GlobalDelegate;
	};

}